package day19;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;

/**
 * 缓冲区的出现是为了提高流的读写效率
 * 缓冲区一出现就必须具有相应的流对象，因此构造函数里面必须传入相应的流对象
 * @author wangbiao
 *
 */
public class BufferedWriterDemo {

	public static void main(String[] args) {

		FileWriter fw = null;
		BufferedWriter bw = null;

		try {
			fw = new FileWriter("buffer.txt");
			bw = new BufferedWriter(fw);
			bw.write("wangbiaodemo");
			bw.newLine();
			bw.write("换行");
			bw.flush();
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			//关闭缓冲区流对象就是关闭本身的流对象
			if (null != bw) {
				try {
					bw.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}
	}
}
